
/**   
*    
* 项目名称：a_yongan   
* 类名称：WarehouseController   
* 类描述：   
* 创建人：liubo   
* 创建时间：2018年6月17日 下午8:25:39    
* 修改时间：2018年6月17日 下午8:25:39   
* 修改备注：   
* @version    
*    
*/
package com.yongan.workflow.web;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.yongan.util.PageBean;
import com.yongan.workflow.entity.PersonalWork;
import com.yongan.workflow.service.PersonalWorkService;

/**
 * @author liubo
 *
 */
@Controller
@RequestMapping("/personalwork")
public class PersonalWorkController {

	@Autowired
	private PersonalWorkService personalWorkService;
	
	@RequestMapping(value = "/personalworkshow", method = RequestMethod.GET)
	public String personalworkcontent(Model model,HttpServletRequest request) {
		List<PersonalWork> personalworklist = null;
		List<PersonalWork> personalworklistup = null;
		String userId = request.getSession().getAttribute("userid").toString();
		personalworklist = personalWorkService.getPersonalWorkList(0, 7, userId);
		personalworklistup = personalWorkService.getPersonalWorkListUp(0, 4, userId);
		model.addAttribute("personalworklist", personalworklist);
		model.addAttribute("personalworklistup", personalworklistup);
		return "personalwork";
	}
	@RequestMapping(value = "/personalworkdaibanlist", method = RequestMethod.GET)
	public String personalworklist(Model model,HttpServletRequest request) {
		List<PersonalWork> personalworklist = null;
		String userId = request.getSession().getAttribute("userid").toString();
		String page = request.getParameter("currentPage");
		int currentPage;
		int totalRecords;
		if (page != null) {
			currentPage = Integer.parseInt(page);
		} else {
			currentPage = 1;
		}
		PageBean<PersonalWork> pb = new PageBean<PersonalWork>();
		totalRecords = personalWorkService.getCount(userId);
		pb.setCurrentPage(currentPage);
		pb.setTotalRecords(totalRecords);
		pb.setTotalPages(pb.getTotalRecords() % pb.getPagesize() == 0 ? pb
				.getTotalRecords() / pb.getPagesize() : pb.getTotalRecords()
				/ pb.getPagesize() + 1);
		if (totalRecords > 0) {
			int start = (pb.getCurrentPage() - 1) * pb.getPagesize();
			int end = pb.getCurrentPage() * pb.getPagesize();
			if (end > totalRecords - 1) {
				end = totalRecords;
			}
			personalworklist = personalWorkService.getPersonalWorkList(start, end, userId);
		}
		model.addAttribute("pb", pb);
		model.addAttribute("personalworklist", personalworklist);
		return "daibanalllist";
	}
	@RequestMapping(value = "/personalworkyibanlist", method = RequestMethod.GET)
	public String personalyibanworklist(Model model,HttpServletRequest request) {
		List<PersonalWork> personalworklist = null;
		String userId = request.getSession().getAttribute("userid").toString();
		String page = request.getParameter("currentPage");
		int currentPage;
		int totalRecords;
		if (page != null) {
			currentPage = Integer.parseInt(page);
		} else {
			currentPage = 1;
		}
		PageBean<PersonalWork> pb = new PageBean<PersonalWork>();
		totalRecords = personalWorkService.getCountYiBan(userId);
		pb.setCurrentPage(currentPage);
		pb.setTotalRecords(totalRecords);
		pb.setTotalPages(pb.getTotalRecords() % pb.getPagesize() == 0 ? pb
				.getTotalRecords() / pb.getPagesize() : pb.getTotalRecords()
				/ pb.getPagesize() + 1);
		if (totalRecords > 0) {
			int start = (pb.getCurrentPage() - 1) * pb.getPagesize();
			int end = pb.getCurrentPage() * pb.getPagesize();
			if (end > totalRecords - 1) {
				end = totalRecords;
			}
			personalworklist = personalWorkService.getPersonalWorkListUp(start, end, userId);
		}
		model.addAttribute("pb", pb);
		model.addAttribute("personalworklist", personalworklist);
		return "yibanalllist";
	}
	
}
